const OpenAI = require("openai");

const openai = new OpenAI({
    baseURL: 'https://api.deepseek.com',
    apiKey: 'sk-bcf5ff8aba97425abf37254ffc26b85a'
});

// 在这里修改您的提示词
const SYSTEM_PROMPT = "你是一个有用的AI助手，请用中文回答问题。";
const USER_QUESTION = "杭州有几个区?";

async function chatWithDeepSeek(systemPrompt = SYSTEM_PROMPT, userQuestion = USER_QUESTION) {
    try {
        const completion = await openai.chat.completions.create({
            messages: [
                { role: "system", content: systemPrompt },
                { role: "user", content: userQuestion }
            ],
            model: "deepseek-chat",
        });

        console.log("🤖 AI回答：", completion.choices[0].message.content);
        return completion.choices[0].message.content;
    } catch (error) {
        console.error("❌ 调用API时发生错误：", error.message);
    }
}

// 主函数
async function main() {
    console.log("🚀 开始与DeepSeek对话...");
    await chatWithDeepSeek();
}

// 如果直接运行此文件
if (require.main === module) {
    main();
}

module.exports = { chatWithDeepSeek, main };